import React from 'react'
import CustomIcon, { CustomIconProps } from "./CustomIcon";
import { IconComponentProps } from '@ant-design/icons/lib/components/AntdIcon'

/**
 * icon 类型
 */
export const EnumIconType = {
  antd: 'antd',
  custom: 'custom'
};

// @ts-ignore
export interface ProAppIconProps extends IconComponentProps {
  appType?: "antd" | "custom";
  iconType: any;
  style?: React.CSSProperties;
  icon?: any;
  CustomIconComponent?: React.FC<CustomIconProps>;
}

/**
 * 应用icon
 * @param appType
 * @param iconType
 * @return {*}
 * @constructor
 */
const ProAppIcon: React.FC<ProAppIconProps> = ({ appType = "custom", iconType, CustomIconComponent, ...rest }) => {
  switch (appType) {
    case EnumIconType.antd:
      const RealIcon = iconType;
      // @ts-ignore
      return <RealIcon {...rest} />;
    case EnumIconType.custom:
      if (CustomIconComponent) {
        return <CustomIconComponent type={iconType as string} {...rest} />
      }
      return <CustomIcon type={iconType as string} {...rest} />;
    default:
      return null
  }
};


export default ProAppIcon;
